package com.project.common.utils;

import com.project.myBeans.ConfigParameters;
import com.taobao.api.DefaultTaobaoClient;
import com.taobao.api.TaobaoClient;
import com.taobao.api.request.AlibabaAliqinFcSmsNumSendRequest;

import java.io.IOException;

/**
 * 与阿里相关的工具
 */
public class AliUtils {

    private static ConfigParameters configParameters=(ConfigParameters) SpringContextUtils.getSpringBean("configParameters");

    //阿里大鱼
    public static TaobaoClient getTaobaoClient() throws IOException {
        TaobaoClient client = new DefaultTaobaoClient(configParameters.getAliDaYuServer(),
                configParameters.getAliDaYuAppKey(),
                configParameters.getAliDaYuSecret());
        return  client;
    }

    //阿里大鱼
    public AlibabaAliqinFcSmsNumSendRequest getAlidayuRequest(String phone, String code, String product, Integer expireMinute, String smsSignName, String smsTemplate){
        AlibabaAliqinFcSmsNumSendRequest req = new AlibabaAliqinFcSmsNumSendRequest();
        req.setSmsType("normal");
        req.setSmsFreeSignName(smsSignName);
        // req.setSmsParamString("{\"code\":\""+code+"\",\"product\":\"UAuth\"}");
        req.setSmsParamString("{\"code\":\""+code+"\",\"product\":\""+product+"\",\"number\":\""+expireMinute+"\"}");
        req.setRecNum(phone);
        req.setSmsTemplateCode(smsTemplate);
        return  req;
    }
}
